package com.example.sensors;

public class AccelCounter {
	private double mTotal;
	private double mCurTotal;
	private double mLimit;

	public AccelCounter() {
		mTotal = mCurTotal = 0.0;
		mLimit = Double.NaN;
	}

	public boolean hasBudget() {
		if (Double.isNaN(mLimit) || (mCurTotal < mLimit)) {
			return true;
		} else if (!Double.isNaN(mLimit) && (mCurTotal >= mLimit)) {
			return false;
		}
		return true;
	}

	public boolean count() {
		if (hasBudget()) {
			mTotal += 1;
			mCurTotal += 1;
			return true;
		} else
			return false;
	}

	public void setLimit(double workLimit) {
		mLimit = workLimit;
		mCurTotal = 0.0;
	}

	public double getCount() {
		return mTotal;
	}

}
